package com.caigou.util;

import java.util.ArrayList;
import java.util.List;

public class Util{

	/**
	 * list超过size个元素时，分割成每size个为一个单独的list
	 * @param list
	 * @return
	 */
	public static <T> List<List<T>> getSumArrayList(List<T> list, int size) {
		List<List<T>> objectlist = new ArrayList<>();
		int iSize = list.size() / size;
		int iCount = list.size() % size;
		for (int i = 0; i <= iSize; i++) {
			List<T> newObjList = new ArrayList<>();
			if (i == iSize) {
				for (int j = i * size; j < i * size + iCount; j++) {
					newObjList.add(list.get(j));
				}
			} else {
				for (int j = i * size; j < (i + 1) * size; j++) {
					newObjList.add(list.get(j));
				}
			}
			if (newObjList.size() > 0) {
				objectlist.add(newObjList);
			}
		}
		return objectlist;
	}
}
